namespace ds
{
    /**
     * 判断是否为2的指数
     * 
     * @param number 整数
     */
    export function isPowerOfTwo(number: number)
    {
        // 1 (2^0) is the smallest power of two.
        if (number < 1)
        {
            return false;
        }

        // Let's find out if we can divide the number by two
        // many times without remainder.
        let dividedNumber = number;
        while (dividedNumber !== 1)
        {
            if (dividedNumber % 2 !== 0)
            {
                // For every case when remainder isn't zero we can say that this number
                // couldn't be a result of power of two.
                return false;
            }

            dividedNumber /= 2;
        }

        return true;
    }
}